<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML>
<html>
  <head>
  	<base href="<%=basePath%>">
    <title>建筑数量</title>
  	<link rel="stylesheet" href="css/vivo.css">
	<link rel="stylesheet" href="css/bootstrap.css">
	<link rel="stylesheet" href="js/bootstrap2/css/bootstrap.min.css">
	<link rel="stylesheet" href="css/common.css">
	<link rel="stylesheet" href="js/font-awesome/css/font-awesome.css">
    <link href="js/select2/select2.min.css" type="text/css" rel="stylesheet" />
	<link rel="stylesheet" type="text/css" href="static/p_house/house_index.css" />
	
	<link rel="stylesheet" type="text/css" href="js/malihu-custom-scrollbar-plugin-master/jquery.mCustomScrollbar.min.css">
	<script type="text/javascript" src="js/jquery-1.11.1.js" ></script>
	<script type="text/javascript" src="js/malihu-custom-scrollbar-plugin-master/jquery.mCustomScrollbar.concat.min.js" ></script>
	<script src="js/bootstrap2/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="js/layui-v2.1.5/layui/layui.all.js"></script> 
	<script type="text/javascript" src="<%=basePath %>js/My97DatePicker/WdatePicker.js"></script> 
	<script src="js/select2/select2.min.js"></script>
    <script type="text/javascript" src="js/sharefunction.js"></script>
	<style type="text/css">
		html,body{
			height: 100%
		}
		.main_l{
			float: left;
			width: 10%;
			height:100%;
			text-align: center;
			overflow-y:auto;
			position:relative;
		}
		.main_r{
			float: left;
			width: 90%;
			height:100%;
			overflow-y:auto;
		}
		.main_l_nav li:not(.add-pic) a{
			width:100%;
			display:inline-block;
		}
		.main_l_nav li:not(.add-pic){
			height:28px;
			line-height:28px;
		}
		.main_l_nav li:not(.add-pic):hover{
			background:#cccccc;
		}
		.main_l_nav li.active{
			background:#cccccc;
		}
		li{
			list-style-type: none;
		}
		.changeBox{
			position:absolute;
			top:20px;
			right:20px;
			margin-left:-20px;
			border:1px solid #ccc;
			background:#ffffff;
			z-index:9999;
		}
		.changeBox>ul{
			margin:0;
		}
		.changeBox>ul>li{
			padding:0 6px; 
		}
		 .changeBox>ul>li:hover{
			background:#ccc;
			cursor: pointer;
		} 
		.changeBox>ul>li.hover{
			background:#ccc
		}
		.triangle{
			border:5px solid #fff
		}
		.textHide{
			text-overflow: ellipsis;
			overflow: hidden;
			white-space: nowrap;
		}
	</style>
	<script type="text/javascript">

		$(function(){
			//获取json数据
			getBuildingNum();

			//初始化滚动条
			initCustomScrollbar();
			$('.main_l_nav').on('click',"li:not(.add-pic)",function(){
				$(this).addClass('active').siblings().removeClass("active");
				
			});
			
			//阻止默认右击事件
			$('.main_l_nav').on("contextmenu","li:not(.add-pic)", function(){
			    return false;
			});
			//取消编辑框
			$('.main_l').on("click",function(){
				$('.changeBox').remove();
			});
			
			//添加右击事件
			$('.main_l_nav').on('mousedown',"li:not(.add-pic)",function(e) {
			    var bid = $(this).find("a").attr("data-id");
			     //右键为1
			    var str=null,top=0,h=$(this).height(),index=$(this).index()+1;
			    console.log(h)
			    	top=index*h-8+"px";
			    if (3 == e.which) {
			    	if($(".changeBox").length>0){	
			    	}else{
			    		str = "<div class=\"changeBox\"><ul><li  class='changeLi' onclick=\"editBuildingNum('"+bid+"','1');\">查看</li>";
				    	<shiro:hasPermission name="permission:edit"> 
							str +="<li  class='changeLi' onclick=\"editBuildingNum('"+bid+"','2');\">编辑</li>";
						</shiro:hasPermission> 
						str+="</ul></div>";
			    		//str="<div class=\"changeBox\"><ul><li onclick=\"editBuildingNum('"+bid+"');\">查看</li><li onclick=\"editBuildingNum('"+bid+"');\">编辑</li></ul></div>";
			       		$('.main_l').append($(str));		
			    	} 
			    	$('.changeBox').css('top',top);	  
			    }
			});
			
			
			/* if($(".changeBox").length>0){
				$('.changeBox').on('mouseover','li',function(){
	       			$(this).addClass('hover').siblings().removeClass('hover');
	       		}).on('mouseleave',"li",function(){
					$('.changeBox').remove();
				})
			} */
		});
		
		//删除楼号
		function delNum(id){
			$.post("buildingNumber/delNum",{id:id},function(data,status){
				if(data.msg=="success"){
					layer.msg("删除成功！");
					location.reload();
				}else if(data.msg=="error"){
					layer.msg("删除失败，请联系系统管理员！");
				}else{
					layer.alert('该建筑下还有有效数据，不能删除', {icon: 7});
				}		
			},"json");
		}
		
		function initCustomScrollbar(){
			 $(window).on("load",function(){
           		 $(".main_l").mCustomScrollbar({
           		 	alwaysShowScrollbar:2,
           		 	theme:"dark"
           		 });
       		 });
		}
		
		
		function getHeight(){
			var ifr=parent.document.getElementsByTagName('iframe');
			var len=0;
			$.each(ifr,function(i,v){
				var $o=$(v);
				if($o.height()>len){
					len=$o.height();
				}
			});
			return len;
			
		}
		
		function getBuildingNum(){
			var	url="buildingNumber/getBuildingNumByPId";
			//pid:项目id
			$.getJSON(url,{pid:parent.parent.projectID},function(data,status){
				if(status=="success"){
					var $tag=$(".main_l ul");
					//加载之前先清空，防止多次调用是重复添加
					$tag.find("li:not(li:last)").remove();
					$.each(data,function(i,v){
						$tag.prepend("<li title=\""+v.buildingName+"\" ><a class=\"textHide\" data-id=\""+v.id+"\" href=\"javascript:void(0);\" onclick=\"openProject('"+v.id+"');\" >"+v.buildingName+"</a></li>");
					});
					//加载成功之后设置默认选中第一项
					var t=$tag.find("li:eq(0) a");
					if(t.length>0){
						t.click();
					}
				}
			});
		}
		function openProject(id){
			$("#buildingFrm")[0].src="buildingNumber/toBuildingNumDetails_"+id;
		}
		function addBuildingNum(){
			var id="";
			var pid = parent.parent.projectID;
			var url = "buildingNumber/toAddOrEdit_"+id+"_"+pid+"_0";
			layer.open({
			  type: 2,
			  title: '新增建筑',
			  shadeClose: true,
			  shade: 0.1,
			  area: ['800px', '500px'],
			  content:url//'p_house/p_num/buildingNum-add.jsp' //iframe的url
			}); 
		}
		//编辑建筑数量
		function editBuildingNum(id,numFlag){
			var pid = parent.parent.projectID;
			var url = "buildingNumber/toAddOrEdit_"+id+"_"+pid+"_"+numFlag;
			layer.open({
			  type: 2,
			  title: '新增建筑',
			  shadeClose: true,
			  shade: 0.1,
			  area: ['800px', '500px'],
			  content: url//'p_house/p_num/buildingNum-add.jsp' //iframe的url
			}); 
		}
	</script>
  </head>
  
  <body>
	<!-- 左侧 -->
	<div class="main_l" id='main_l'>
		<ul style="margin-left:10px" class='main_l_nav'>
			<li class="add-pic"><img alt="" src="images/add.png" onclick="addBuildingNum();" style="cursor:pointer;" ></li>
		</ul>
	</div>
	<!-- 右侧 -->
	<div class="main_r">
		<!-- 要打开的页面 buildingNumber/toBuildingNumDetails_ 需要传入id -->
		<iframe id="buildingFrm" src="" width="100%" style="height: calc(100% - 5px);" frameborder="0" ></iframe>
	</div>
  </body>
</html>
